package com.ruoyi.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.system.domain.Room;
import com.ruoyi.system.mapper.RoomMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BackInfoMapper;
import com.ruoyi.system.domain.BackInfo;
import com.ruoyi.system.service.IBackInfoService;
import com.ruoyi.common.core.text.Convert;

/**
 * 退住信息Service业务层处理
 * 
 * @author 王帅
 * @date 2024-08-25
 */
@Service
public class BackInfoServiceImpl extends ServiceImpl<BackInfoMapper,BackInfo> implements IBackInfoService

{
    @Autowired
    private BackInfoMapper backInfoMapper;
    @Autowired
    private RoomMapper roomMapper;

    /**
     * 查询退住信息
     * 
     * @param id 退住信息主键
     * @return 退住信息
     */
    @Override
    public BackInfo selectBackInfoById(Long id)
    {
        return backInfoMapper.selectBackInfoById(id);
    }

    /**
     * 查询退住信息列表
     * 
     * @param backInfo 退住信息
     * @return 退住信息
     */
    @Override
    public List<BackInfo> selectBackInfoList(BackInfo backInfo)
    {
        return backInfoMapper.selectBackInfoList(backInfo);
    }

    /**
     * 新增退住信息
     * 
     * @param backInfo 退住信息
     * @return 结果
     */
    @Override
    public int insertBackInfo(BackInfo backInfo)
    {
        backInfo.setCreateTime(DateUtils.getNowDate());
        backInfo.setUpdateTime(DateUtils.getNowDate());
        Room room = roomMapper.selectRoomById(backInfo.getBackRoom());
        backInfo.setBackRoom(room.getId());
        backInfo.setBackRoomNumber(room.getRoomNumber());
        SysUser sysUser = ShiroUtils.getSysUser();
        String userName = sysUser.getUserName();
        backInfo.setCreateBy(userName);
        return backInfoMapper.insertBackInfo(backInfo);
    }

    /**
     * 修改退住信息
     * 
     * @param backInfo 退住信息
     * @return 结果
     */
    @Override
    public int updateBackInfo(BackInfo backInfo)
    {
        backInfo.setUpdateTime(DateUtils.getNowDate());
        Room room = roomMapper.selectRoomById(backInfo.getBackRoom());
        backInfo.setBackRoom(room.getId());
        backInfo.setBackRoomNumber(room.getRoomNumber());
        return backInfoMapper.updateBackInfo(backInfo);
    }

    /**
     * 批量删除退住信息
     * 
     * @param ids 需要删除的退住信息主键
     * @return 结果
     */
    @Override
    public int deleteBackInfoByIds(String ids)
    {
        return backInfoMapper.deleteBackInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除退住信息信息
     * 
     * @param id 退住信息主键
     * @return 结果
     */
    @Override
    public int deleteBackInfoById(Long id)
    {
        return backInfoMapper.deleteBackInfoById(id);
    }
}
